<template>
	<view class="content">
		
		<!-- 头部教师信息 -->
		<view class="teacher-info">
			<view class="detail">
				<!-- 头像 -->
				<view class="detail-img">
					<view class="detail-img-name">
						<image style="width: 140rpx;height: 140rpx;border-radius: 50%;" :src="userinfo.head_portrait"
							mode=""></image>
						<text class="name">{{userinfo.nickname}}</text>
					</view>
					<view class="detail-heart" @tap="doheart" style="margin-left: 15rpx;">
						<uni-icons type="plusempty" color="#333333" v-if="!userinfo.isSubscribe"></uni-icons>
						<text style="color: #333333;">{{userinfo.isSubscribe?"已关注":"关注"}}</text>
					</view>
				</view>
				<!-- 数据 -->
				<view class="detail-data">
					<view class="detail-data-item">
						<text class="data-item-num">0</text>
						<text class="data-item-tip">学生</text>
					</view>
					<view class="detail-data-item">
						<text class="data-item-num">{{userinfo.shopList && userinfo.shopList.length ? userinfo.shopList.length : '0'}}</text>
						<text class="data-item-tip">视频</text>
					</view>
					<view class="detail-data-item">
						<text class="data-item-num">{{videoList && videoList.length ? videoList.length : '0'}}</text>
						<text class="data-item-tip">合集</text>
					</view>
				</view>
				<!-- 作者简介 -->
				<text class="detail-desc">{{userinfo.introduce}}</text>
				<!-- 选项卡 -->
				<view class="video-tab">
					<text class="tab-item" v-for="(tab,index) in tabs" :class="tabIndex==index ? 'tab-item-active' : ''"
						:data-current="index" @click="tabchange">{{tab}}</text>
				</view>
			</view>
		</view>
		<!-- 内容区 -->
		<view class="lists">
			<!-- 视频 -->
			<view :class="tabIndex==1 ? 'theItemOff' : ''"
				style="display: flex;justify-content: space-between;box-sizing: border-box;">
				<view class="videos-left video-lsits">
					<view class="video-item" v-for="(item, i) in userinfo.shopList" :key="i" @tap.stop='toPlayVideo(item)'>
						<!-- <image class="video-item-img" :src="item." mode="aspectFill"></image> -->
						<template v-if="(i + 1) % 2 != 0">
							<view class="item-img-box">
								<image class="video-item-img" :src="item.cover_url" mode="aspectFill"></image>
							</view>
							<view class="video-item-time">
								<text style="color: #FFFFFF;font-size: 20rpx;">{{item.video_time | filterVideoTime}}</text>
							</view>
							<view class="video-item-desc">
								<text style="color: #333333;font-weight: bold;padding-top: 10rpx;">{{item.title || ''}}</text>
								<text style="color: #666666;padding-top: 10rpx;">{{item.describe || ''}}</text>
								<!-- <text style="text-align: end;padding-top: 20rpx;color: #737373;"></text> -->
							</view>
						</template>
					</view>
				</view>
				<view class="videos-right video-lsits">
					<view class="video-item" v-for="(item, i) in userinfo.shopList" :key='i' @tap.stop='toPlayVideo(item)'>
						<template v-if="(i + 1) % 2 == 0">
							<view class="item-img-box">
								<image class="video-item-img" :src="item.cover_url" mode="aspectFill"></image>
							</view>
							<view class="video-item-time">
								<text style="color: #FFFFFF;font-size: 20rpx;">{{item.video_time | filterVideoTime}}</text>
							</view>
							<view class="video-item-desc">
								<text style="color: #333333;font-weight: bold;padding-top: 10rpx;">{{item.title || ''}}</text>
								<text style="color: #666666;padding-top: 10rpx;">{{item.describe || ''}}</text>
								<!-- <text style="text-align: end;padding-top: 20rpx;color: #737373;">麦冬</text> -->
							</view>
						</template>
					</view>
				</view>
			</view>
			<!-- 合集 -->
			<view class="video-lsits" :class="tabIndex==0 ? 'theItemOff' : ''">
				<view class="video-list-items" v-for="(item, i) in videoList" :key='i' @tap="groupContent(item.id)">
					<view class="video-list-items-img">
						<image :src="item.img" mode="aspectFill"></image>
						<!-- <view class="video-list-items-img-time">
							<text style="color: #FFFFFF;font-size: 20rpx;">20个视频</text>
						</view> -->
					</view>
					<view class="video-list-items-desc">
						<text style="color: #1A1A1A;font-weight: bold;">{{item.title || ''}}</text>
						<!-- <text style="color: #4D4D4D;">这里是课程集合描述，后台限制字数，简单介绍。</text> -->
						<!-- <view class="video-list-items-desc-price">
							<text style="color: #B91C27;">查看合集</text>
						</view> -->
					</view>
				</view>
			</view>
		</view>
		
		
		<!-- 视频合集 groupList -->
		<uni-popup ref="group-list" type="bottom" style="z-index: 20000;">
			<view class="morevideo">
				<view class="video-title-close">
					<view class="video-list-name">
						<view class="video-title-icon"></view>
						<text class="video-title">课程合集</text>
					</view>
					<uni-icons type="close" size="22" color="#707070" @click="groupClose"></uni-icons>
				</view>
				<view class="video-lsits">
					<scroll-view :scroll-y="true" :show-scrollbar="false" style="height: 800rpx;">
						<view class="video-list-items" v-for="(item, i) in groupList" :key="i" @tap="toPlayVideoMain(item)">
							<view class="video-list-items-img">
								<image :src="item.cover_url"
									mode="aspectFill"></image>
								<view class="video-list-items-img-time">
									<text
										style="color: #FFFFFF;font-size: 20rpx;">{{item.video_time | filterVideoTime}}</text>
								</view>
							</view>
							<view class="video-list-items-desc">
								<text style="color: #1A1A1A;font-weight: bold;">{{item.title || ''}}</text>
								<text style="color: #4D4D4D;">{{item.describe || ''}}</text>
								<view class="video-list-items-desc-price">
									<text style="color: #B91C27;">￥{{item.price}}</text>
									<!-- <uni-icons type="cart-filled" size="20" color="#B91C27"></uni-icons> -->
								</view>
							</view>
						</view>
					</scroll-view>
				</view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				// 选项卡
				tabs: ["视频", "合集"],
				tabItem: 'tab-item tab-item-active',
				tabIndex: 0,
				// 关注
				heart: "已关注",
				isheart: false,
				// 合集
				videoLists: [1, 2, 3, 4],
				// 老师个人信息
				userinfo: {},
				videoList: [],
				id: '',
				
				groupQuery: {
					group: '',
					offset: 1,
					limit: 10
				},
				groupList: [],
				showMark: false, // 遮罩层
			}
		},
		onLoad(o) {
			this.id = o.id
			this.getTeacherInfo()
			this.getVideoList()
		},
		filters: {
			filterVideoTime(time) {
				if (!time) {
					return ''
				}
				const second = parseInt(time / 60)
				const minute = (time % 60 + '').slice(0, 2)
				return `${second < 10 ? '0' + second : second}:${minute < 10 ? '0' + minute : minute}`
			},
			
		},
		methods: {
			// 合集内容
			async groupContent(id) {
				
				this.showMark = true
				this.$refs['group-list'].open()
				this.groupQuery.group = id
				const res = await this.$http.request('/api/v1/shop/group', this.groupQuery, 'GET')
				if (res.code == 200) {
					this.groupList = res.data.data
				}
			
			},
			groupClose() {
				this.$refs['group-list'].close()
				this.showMark = false
			},
			// 获取老师信息
			async getTeacherInfo() {
				const res = await this.$http.request('/api/v1/author/show', {
					id: this.id
				}, 'GET')
				if (res.code == 200) {
					this.userinfo = res.data

				}
			},
			// 获取视频列表
			async getVideoList() {
				const res = await this.$http.request('/api/v1/author/group', {
					member_id: this.id
				}, 'GET')
				if (res.code == 200) {
					this.videoList = res.data
				}
			},
			// 上传封面
			async uploadImage() {
				const res = await this.$http.request('')
			},
			// 获取合计列表
			// async getMountList() {
			// 	const res = await this.$http.request('')
			// },
			// 选项卡切换
			tabchange(e) {
				let index = e.target.dataset.current || e.currentTarget.dataset.current;
				console.log(e.target)
				if (index != this.tabIndex) {
					this.tabIndex = index
				}
			},
			// 关注
			// uni.getStorageSync('userID')
			async doheart() {
				const query = {id: this.id}
				const res = await this.$http.request('/api/v1/author/subscribe', query, 'POST')
				if (res.code == 200) {
					if (res.data == '取消关注') {
						this.userinfo.isSubscribe = false
					} else if (res.data == '关注成功') {
						this.userinfo.isSubscribe = true
					}
					
					// return uni.$toast('关注成功')
				}
				// uni.$toast('关注失败')
			},
			toPlayVideo(item) {
				uni.navigateTo({
					url: '/pages/teacher/video-play?videoInfo=' + JSON.stringify(item)
					// url: '/pages/teacher/video-common?videoInfo=' + JSON.stringify(item)
				})
			},
			toPlayVideoMain(item) {
				uni.navigateTo({
					url: '/pages/teacher/video-play?videoInfo=' + JSON.stringify(item)
				})
			},
			showPop() {
				this.$refs.popup.open('bottom')
			}
		}
	}
</script>

<style lang="scss" scoped>
	
	.lists {
		padding-right: 20rpx;
		.item-img-box {
			position: relative;
			.fengmian {
				@include flex-center(100%, 80rpx);
				position: absolute;
				bottom: 5rpx;
				left: 0;
				background-color: rgba($color: #000000, $alpha: .5);
				color: #FFFFFF;
			}
		}
	}
	.content {
		background-color: #EFEEF6;
	}

	.teacher-info {
		height: 560rpx;
		background-color: #f2f2f2;
		display: flex;
		flex-direction: column;
		justify-content: flex-end;
	}

	.detail {
		padding: 0 30rpx;
		border-radius: 40rpx 40rpx 0 0;
		background-color: #fff;
		height: 400rpx;
		position: relative;
		display: flex;
		flex-direction: column;
		justify-content: flex-end;
	}

	/* 头像和关注 */
	.detail-img {
		display: flex;
		justify-content: space-between;
		align-items: center;
		// width: 300rpx;
		position: absolute;
		top: -50rpx;
	}

	.name {
		color: #4D4D4D;
		font-size: 40rpx;
		font-weight: bold;
	}

	.detail-img-name {
		display: flex;
		flex-direction: column;
		align-items: center;
	}

	/* 关注 */
	.detail-heart {
		padding: 4rpx 20rpx;
		border: 3rpx solid #B91C27;
		border-radius: 40rpx;
	}

	/* 数据 */
	.detail-data {
		display: flex;
		width: 100%;
		justify-content: flex-end;
		padding-right: 30rpx;
		box-sizing: border-box;
	}

	.detail-data-item {
		display: flex;
		flex-direction: column;
		align-items: center;
		padding-left: 50rpx;
	}

	.data-item-num {
		color: #4D4D4D;
		font-size: 40rpx;
	}

	.data-item-tip {
		color: #808080;
		font-size: 30rpx;
	}

	.detail-desc {
		color: #808080;
		padding: 30rpx 20rpx;
	}

	/* 选项卡 */
	.video-tab {
		display: flex;
		justify-content: space-around;
		align-items: center;
		padding: 0 200rpx;
		padding-top: 10rpx;
	}

	.tab-item {
		color: #666666;
		font-size: 34rpx;
	}

	.tab-item-active {
		color: #B91C27;
		font-size: 40rpx;
		padding-bottom: 10rpx;
		border-bottom: 3rpx solid #B91C27;
	}

	.theItemOff {
		
		display: none !important;
	}

	/* 集合列表 */
	.video-lsits {
		padding: 20rpx;
		padding-right: 0;
		display: flex;
		flex-wrap: wrap;
		justify-content: space-between;
	}

	.video-list-items {
		width: 100%;
		height: 251rpx;
		background: #FFFFFF;
		border-radius: 10rpx;
		display: flex;
		justify-content: space-between;
		padding: 20rpx;
		margin-bottom: 20rpx;
		
	}

	.video-list-items-img {
		// @include flex-center(240rpx, 198rpx);
		width: 240rpx;
		height: 198rpx;
		position: relative;
		flex-direction: column;
		justify-content: center;
		border-radius: 20rpx;
		overflow: hidden;
		& > image {
			width: 240rpx;
			height: 100%;
			border-radius: 20rpx;
		}
	}

	.video-list-items-img-time {
		background-color: rgba(0, 0, 0, 0.4);
		width: 160rpx;
		height: 50rpx;
		text-align: center;
		display: flex;
		align-items: center;
		justify-content: center;
		position: absolute;
		top: 0;
		left: 0;
		border-radius: 20rpx 0 50rpx 0;
	}

	.video-list-items-desc {
		display: flex;
		flex-direction: column;
		justify-content: space-around;
		// margin-left: 40rpx;
		width: 366rpx;
		height: 210rpx;
	}

	.video-list-items-desc-price {
		display: flex;
		justify-content: flex-end;
	}

	/* 视频 */
	.video-item {
		position: relative;
		display: flex;
		flex-direction: column;
		justify-content: flex-start;
		background-color: #fff;
		border-radius: 20rpx;
		width: 345rpx;
		margin-bottom: 20rpx;
		box-sizing: border-box;
	}

	.video-item-time {
		background-color: rgba(0, 0, 0, 0.4);
		width: 140rpx;
		height: 50rpx;
		text-align: center;
		display: flex;
		align-items: center;
		justify-content: center;
		position: absolute;
		top: 0;
		left: 0;
		border-radius: 20rpx 0 50rpx 0;
	}

	.video-item-img {
		width: 345rpx;
		height: 320rpx;
		border-radius: 20rpx 20rpx 0 0;
	}

	.video-item-desc {
		padding: 20rpx 10rpx;
		display: flex;
		flex-direction: column;
	}

	.videos-left,
	.videos-right {
		width: 345rpx;
	}

	.videos-right {
		padding-left: 0;
		flex-direction: column;
		justify-content: flex-start;
	}

	.videos-right .video-item-img {
		height: 260rpx;
	}
	
	/* 更多视频 */
	.morevideo {
		position: relative;
		height: 900rpx;
		border-radius: 20rpx 20rpx 0 0;
		background-color: white;
		padding: 20rpx;
	
		.price-box {
			@include flex-between(100%, 120rpx);
			position: fixed;
			bottom: 0;
			left: 0;
			background-color: #FFFFFF;
			box-shadow: 5rpx 0 10rpx rgba($color: #000000, $alpha: .3);
			padding: 0 20rpx 0 46rpx;
			z-index: 9999;
	
			.left-radio {
				.title {
					margin-left: 16rpx;
					font-size: 28rpx;
					color: #4D4D4D;
				}
			}
	
			.amount-box {
				display: flex;
				align-items: center;
	
				.amount {
					font-size: 28rpx;
					color: #4D4D4D;
					margin-right: 8rpx;
				}
	
				.price {
					font-size: 24rpx;
					color: #B91C27;
				}
			}
	
			.confirm-btn {
				@include flex-center(318rpx, 88rpx);
				background: #B91C27;
				border-radius: 44rpx;
				font-size: 36rpx;
				color: #FFFEFE;
			}
	
		}
	}
	
	.video-title-close {
		box-sizing: border-box;
		padding-top: 10rpx;
		margin-bottom: 40rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;
	}
	
	.video-list-name {
		display: flex;
		align-items: center;
	}
	
	.video-title {
		font-weight: bold;
		color: #4D4D4D;
		letter-spacing: 2rpx;
		box-sizing: border-box;
	}
	
	.video-title-icon {
		width: 12rpx;
		height: 40rpx;
		border-radius: 20rpx;
		margin-right: 20rpx;
		background-color: #B91C27;
	}
</style>
